﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace ViewMaker.Core.Controls
{
    /// <summary>
    /// データグリッド列共通
    /// </summary>
    public abstract class DataGridColumnViewElement : ViewElement
    {
        public new class Properties : ViewElement.Properties
        {
            public const string Width = "Width";
            public const string IsReadOnly = "IsReadOnly";
        }

        /// <summary>
        /// コントロール幅
        /// </summary>
        [Display(GroupName = LayoutGroup)]
        public int? Width
        {
            get { return _width; }
            set { if (_width != value) { _width = value; OnPropertyChanged("Width"); } }
        }
        private int? _width;

        /// <summary>
        /// 読み取り専用
        /// </summary>
        [DefaultValue(false)]
        public virtual bool IsReadOnly { get; set; }

        public DataGridColumnViewElement()
        {
            IsDataGridItem = true;
        }

        protected override void ApplyBaseProperty(XamlNode node)
        {
#if !SILVERLIGHT
            if (!string.IsNullOrWhiteSpace(Item.Name)) node.SetAttribute("x:Name", "http://schemas.microsoft.com/winfx/2006/xaml", Item.Name);
#else
            if (!string.IsNullOrWhiteSpace(Item.Name)) node.SetAttribute("Name", "http://schemas.microsoft.com/winfx/2006/xaml", Item.Name);
#endif

            if (!string.IsNullOrEmpty(Item.Caption)) node.SetAttribute("Header", Item.Caption);
            if (Width.HasValue) node.SetAttribute("Width", Width.ToString());
            if (IsReadOnly) node.SetAttribute("IsReadOnly", IsReadOnly.ToString());
            foreach (var tag in AdditionalProperty)
            {
                node.SetAttribute(tag.Key, tag.Value);
            }
        }

        internal override void CopyFrom(ViewElement source)
        {
        }

    }
}
